<template>
    <div class="samebox">
        <div class="q_xxpxjl">
            <img src="../assets/renzhiqian.png" alt="">
            <div> 任职后主要专业技术工作业绩登记</div>
        </div>
        <div class="q_zssx" style="text-align: right">
            <el-row>
                <el-button type="primary" size="medium" class="el-icon-s-promotion" @click="dialogVisible=true">新增
                </el-button>
                <el-popconfirm
                        confirm-button-text='好的'
                        cancel-button-text='不用了'
                        icon="el-icon-info"
                        icon-color="red"
                        title="确定要删除选中的数据吗？"
                        @confirm="removeAfter()"
                >
                    <el-button class="el-icon-delete" size="medium" slot="reference" style="margin-left: 10px">删除
                    </el-button>
                </el-popconfirm>
            </el-row>
        </div>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr class="q_xuhao">
                    <td>序号</td>
                    <td>起始时间</td>
                    <td>结束时间</td>
                    <td style="width: 400px">专业技术工作名称（项目、课题）</td>
                    <td>工作内容、本人起何作用</td>
                    <td>完成情况及效果</td>
                </tr>
                </thead>
                <tbody v-if="afterData.length>0">
                <tr v-for="(item,index) in afterData">
                    <td>
                        <input type="checkbox" @change="selectItem(item.id)">
                        <span>{{index+1}}</span>
                    </td>
                    <td>{{item.fqssj}}</td>
                    <td>{{item.fjssj}}</td>
                    <td>
                        <el-popover trigger="hover">
                            <span>{{item.fzyjsgzmc}}</span>
                            <div slot="reference" class="name-wrapper ellipsis max_width">
                                {{item.fzyjsgzmc}}
                            </div>
                        </el-popover>
                    </td>
                    <td>
                        <el-popover trigger="hover">
                            <span>{{item.fgznrbrqhzy}}</span>
                            <div slot="reference" class="name-wrapper ellipsis medium_width">
                                {{item.fgznrbrqhzy}}
                            </div>
                        </el-popover>
                    </td>
                    <td>
                        <el-popover trigger="hover">
                            <span>{{item.fwcqkjxg}}</span>
                            <div slot="reference" class="name-wrapper ellipsis min_width">
                                {{item.fwcqkjxg}}
                            </div>
                        </el-popover>
                    </td>
                </tr>
                </tbody>
                <tr v-else>
                    <td colspan="6">
                        <el-empty></el-empty>
                    </td>
                </tr>
            </table>
        </div>
        <!--    弹出框    -->
        <el-dialog
                title="填写表单"
                :visible.sync="dialogVisible"
                width="30%">
            <!--  -->
            <el-form :model="afterRule" :rules="rules" ref="afterRule" label-width="100px">
                <el-form-item label="工作名称" prop="fzyjsgzmc">
                    <el-input v-model="afterRule.fzyjsgzmc" placeholder="专业技术工作名称（项目、课题）"></el-input>
                </el-form-item>
                <el-form-item label="起始时间" required>
                    <el-form-item prop="fqssj">
                        <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                                        v-model="afterRule.fqssj"
                                        style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="结束时间" required>
                    <el-form-item prop="fjssj">
                        <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                                        v-model="afterRule.fjssj"
                                        style="width: 100%;"></el-date-picker>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="工作内容" prop="fgznrbrqhzy">
                    <el-input v-model="afterRule.fgznrbrqhzy" placeholder="工作内容"></el-input>
                </el-form-item>
                <el-form-item label="完成情况" prop="fwcqkjxg">
                    <el-input v-model="afterRule.fwcqkjxg" placeholder="完成情况"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('afterRule')">提交</el-button>
                    <el-button @click="resetForm('afterRule')">重置</el-button>
                </el-form-item>
            </el-form>
            <!---->
        </el-dialog>
        <!---->
        <div class="q_sub">
            <el-pagination
                    background
                    layout="prev, pager, next"
                    :current-page.sync="currentPage"
                    :hide-on-single-page="hidePage"
                    :page-size="pageSize"
                    :total="total"
                    @current-change="queryAfterInfo">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    import "../assets/samecss/same.css"

    export default {
        name: "OfficeBefore",
        created() {
            this.queryAfterInfo()
        },
        methods: {
            //提交表单
            submitForm(formName) {
                let that = this;
                that.$refs[formName].validate((valid) => {
                    if (valid) {
                        that.$http.post("/ofafter/ofafteradd", that.afterRule).then(res => {
                            that.$message.success("添加成功");
                            that.queryAfterInfo();
                            that.resetForm(formName);
                            // that.dialogVisible=false
                        })
                    } else {
                        return false;
                    }
                });
            },
            //重置表单
            resetForm(formName) {
                this.afterRule = {};
                this.$refs[formName].clearValidate();
            },
            //选中数据
            selectItem(id) {
                let index = this.ids.indexOf(id);
                if (index > -1) {
                    this.ids.splice(index, index + 1)
                } else {
                    this.ids.push(id)
                }
            },
            //删除数据
            removeAfter() {
                let that = this
                if (that.ids.length == 0) {
                    that.$message.warning('您还没有选择要删除的数据')
                    return
                }
                that.$http.post("/ofafter/ofafterdle", that.ids).then(res => {
                    that.$message.success('删除成功')
                    that.queryAfterInfo();
                    that.ids = []

                })
            },
            //后台查询展示列表
            queryAfterInfo() {
                let that = this;
                that.$http.get('/ofafter/ofafterslt', {
                    params: {
                        currentPage: that.currentPage,
                        pageSize: that.pageSize
                    }
                }).then(res => {
                    that.afterData = res.data.list
                    that.currentPage = res.data.currentPage
                    that.total = res.data.total
                })
            }

        },
        data() {
            const validateEndTime = (rule, value, callback) => {
                if (value === '' || value == null) {
                    callback(new Error('请选择日期'))
                } else {
                    if (
                        new Date(this.afterRule.fqssj).getTime() >=
                        new Date(this.afterRule.fjssj).getTime()
                    ) {
                        callback(new Error('截止时间必须大于开始时间！'))
                    } else {
                        callback()
                    }
                }
            };
            return {
                ids: [],
                total:1,
                currentPage: 1,
                pageSize: 10,
                hidePage: true,
                //弹出框显示隐藏
                dialogVisible: false,
                //表数据
                afterData: [],
                //弹出框验证表单内容
                afterRule: {
                    fzyjsgzmc: '',
                    fqssj: '',
                    fjssj: '',
                    fgznrbrqhzy: '',
                    fwcqkjxg: '',
                },
                //el验证
                rules: {
                    fzyjsgzmc: [
                        {required: true, message: '工作名称（项目、课题）', trigger: 'blur'},
                        {min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur'}
                    ],
                    fqssj: [
                        {required: true, message: '请选择日期', trigger: 'blur'}
                    ],
                    fjssj: [
                        {validator: validateEndTime, required: true, trigger: 'blur'}
                    ],
                    fgznrbrqhzy: [
                        {required: true, message: '工作内容', trigger: 'blur'},
                        {min: 3, max: 200, message: '长度在 3 到 200 个字符', trigger: 'blur'}
                    ],
                    fwcqkjxg: [
                        {required: true, message: '完成情况', trigger: 'blur'},
                        {min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur'}
                    ],
                },

            }
        },
    }
</script>

<style scoped>

</style>
